package thread;

/**
 * 线程创建的第二种方式
 * 使用实现Runnable接口单独定义线程任务
 */
public class ThreadDemo2 {
    public static void main(String[] args) {

        // 创建线程任务对象
        Runnable r1 = new myRunnable();
        Runnable r2 = new myRunnable1();

        // 创建线程
        Thread t1 = new Thread(r1);
        Thread t2 = new Thread(r2);

        t1.start();
        t2.start();

    }
}
class myRunnable implements Runnable{
    public void run() {
        for(int i = 0; i < 100; i++){
            System.out.println("线程1任务执行");
        }

    }
}

class myRunnable1 implements Runnable{
    public void run() {
        for(int i = 0; i < 100; i++){
            System.out.println("线程2任务执行");
        }

    }
}

